//
//  liulanViewController.m
//  movie
//
//  Created by 白浩洋 on 2018/4/11.
//  Copyright © 2018年 白浩洋. All rights reserved.
//

#import "liulanViewController.h"
#import "MoviePlayViewController.h"
@interface liulanViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSMutableArray *dataSource;
@property (nonatomic,strong)UITableView *tabView;

@end

@implementation liulanViewController
{
    NSInteger index;
    BOOL isDown;
    NSMutableArray *DateArr;
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.tabView reloadData];
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addCustomTitleWithTitle:@"我的收藏"];
    [SVProgressHUD showInfoWithStatus:@"正在加载中。。。"];
    [SVProgressHUD dismissWithDelay:0.5];
    [self.tabView reloadData];
}

-(NSMutableArray *)dataSource{
    if(!_dataSource){
        _dataSource = [[NSMutableArray alloc]initWithArray:[NBATools getshoucang]];
    }
    return _dataSource;
}
- (UITableView *)tabView{
    if(!_tabView){
        _tabView = [[UITableView alloc]initWithFrame:CGRectMake(0,PXChange(20), ScreenWidth, self.view.height - PXChange(20) -iPhoneXTabHeigth - 64)];
        _tabView.delegate = self;
        _tabView.dataSource =self;
        _tabView.separatorStyle = UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tabView];
    }
    return _tabView;
}
#pragma mark - tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataSource.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return PXChange(200);
}
#pragma mark - tableViewDelegate
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    if(!cell){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"cell"];
    }
    [cell.contentView removeAllSubviews];
    UIImageView *image = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, PXChange(240), PXChange(160))];
    [image sd_setImageWithURL:[NSURL URLWithString:self.dataSource[indexPath.row][@"imgurl"]] placeholderImage:[UIImage imageNamed:@"jpghold"]];
    image.center = CGPointMake(PXChange(10) + image.width/2.0f, PXChange(100));
    [cell.contentView addSubview:image];
    UILabel *lab = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth - PXChange(300), 0)];
    lab.text = self.dataSource[indexPath.row][@"des"];;
    lab.textColor = [UIColor colorWithHexString:@"#333333"];
    lab.font = [UIFont systemFontOfSize:PXChange(28)];
    lab.numberOfLines = 0;
    [lab sizeToFit];
    lab.center = CGPointMake(image.right + PXChange(20) + lab.width/2.0f, image.top + lab.height/2.0f);
    [cell.contentView addSubview:lab];
    UILabel *yuedulab = [[UILabel alloc]initWithFrame:CGRectZero];
    yuedulab.text = [NSString stringWithFormat:@"%@次数观看",self.dataSource[indexPath.row][@"yuedu"]];
    yuedulab.textColor = [UIColor colorWithHexString:@"#666666"];
    yuedulab.font = [UIFont systemFontOfSize:PXChange(15)];
    yuedulab.numberOfLines = 0;
//    [yuedulab sizeToFit];
    yuedulab.center = CGPointMake(image.right + PXChange(20) + yuedulab.width/2.0f, PXChange(200) - yuedulab.height/2.0f - PXChange(20));
    [cell.contentView addSubview:yuedulab];
    UILabel *shoujialab = [[UILabel alloc]initWithFrame:CGRectZero];
    shoujialab.text =[NSString stringWithFormat:@"收取:%@星",self.dataSource[indexPath.row][@"shoujia"]];
    shoujialab.textColor = [UIColor colorWithHexString:@"#666666"];
    shoujialab.font = [UIFont systemFontOfSize:PXChange(15)];
    shoujialab.numberOfLines = 0;
//    [shoujialab sizeToFit];
    shoujialab.center = CGPointMake(yuedulab.right + PXChange(40) + shoujialab.width/2.0f, yuedulab.centerY);
    [cell.contentView addSubview:shoujialab];
    UILabel *shichang = [[UILabel alloc]initWithFrame:CGRectZero];
    if(self.dataSource[indexPath.row][@"shichang"]){
        shichang.text = [NSString stringWithFormat:@"时长:%@分",self.dataSource[indexPath.row][@"shichang"]];
    }
    shichang.textColor = [UIColor colorWithHexString:@"#333333"];
    shichang.font = [UIFont systemFontOfSize:PXChange(15)];
    shichang.numberOfLines = 0;
    [shichang sizeToFit];
    shichang.center = CGPointMake(shoujialab.right + PXChange(40) + shichang.width/2.0f, yuedulab.centerY);
    [cell.contentView addSubview:shichang];
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MoviePlayViewController *mv = [[MoviePlayViewController alloc]init];
    mv.hidesBottomBarWhenPushed = YES;
    mv.MovieName =self.dataSource[indexPath.row][@"des"];
    mv.MovieUrl =self.dataSource[indexPath.row][@"videoUrl"];
    mv.shoucangdic = self.dataSource[indexPath.row];
    [self.navigationController pushViewController:mv animated:YES];
}
@end
